import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { PathItem } from "../../views/Functions/children/Upload/Upload";

// export const deviceSlice = createSlice<typeof data,>(data)

export type CutBoardType = { name: string; path: PathItem[] }[];
const cutBoard: CutBoardType = [];
const pageInfo = {
  pageNo: 1,
  pageSize: 10,
  total: 0,
};

export type PageInfoType = typeof pageInfo;

export const uploadSlice = createSlice({
  name: "upload",
  initialState: {
    cutBoard,
    pageInfo,
  },
  reducers: {
    updatePageInfo: (state, action: PayloadAction<Partial<PageInfoType>>) => {
      return {
        ...state,
        pageInfo: {
          ...state.pageInfo,
          ...action.payload,
        },
      };
    },
    updateCutBoard: (state, action: PayloadAction<CutBoardType>) => {
      return {
        ...state,
        cutBoard: action.payload,
      };
    },
  },
});

export const uploadReducer = uploadSlice.reducer;

export const { updateCutBoard, updatePageInfo } = uploadSlice.actions;
